{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv('iris_dataset.csv')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 150 entries, 0 to 149\n", "Data columns (total 5 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 sepal_length 150 non-null float64\n", " 1 sepal_width 150 non-null float64\n", " 2 petal_length 150 non-null float64\n", " 3 petal_width 150 non-null float64\n", " 4 species 150 non-null object \n", "dtypes: float64(4), object(1)\n", "memory usage: 6.0+ KB\n" ] } ], "source": [ "data.info()" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "# feature = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']\n", "# predection_class = ['species']" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "X = data.drop(columns=['species'])\n", "y = data['species']" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape of X_test is (45, 4)\n", "Shape of X_train is (105, 4)\n", "Shape of Y_test is (45,)\n", "Shape of Y_train is (105,)\n" ] } ], "source": [ "from sklearn.model_selection import train_test_split\n", "X_train, X_test, Y_train, Y_test = train_test_split(X,y,test_size=0.30)\n", "print(f\"Shape of X_test is {X_test.shape}\")\n", "print(f\"Shape of X_train is {X_train.shape}\")\n", "print(f\"Shape of Y_test is {Y_test.shape}\")\n", "print(f\"Shape of Y_train is {Y_train.shape}\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from sklearn.ensemble import AdaBoostClassifier\n", "clf = AdaBoostClassifier()\n", "clf.fit(X_train, Y_train)\n", "Y_pred = clf.predict(X_test)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accuracy 93.33333333333333\n" ] } ], "source": [ "from sklearn import metrics\n", "print(\"Accuracy\", metrics.accuracy_score(Y_test, Y_pred)*100)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }